﻿using System;
using System.Collections.Generic;
using System.Xml.Linq;
using Volo.Abp.Domain.Entities;
using static System.Net.Mime.MediaTypeNames;

namespace Abp.vNext.WT.WebApi.Issues
{
    public class Issue : AggregateRoot<Guid>
    {
        public string Title { get; set; }
        public string Description { get; set; }
        public bool IsLocked { get; set; }
        public bool IsClosed { get; private set; }
        public DateTime? CloseDate { get; private set; }

        /// <summary>
        /// 用户(领域)的Id
        /// </summary>
        public Guid? AssignedUserId { get; internal set; }//No validation

        public void Close()
        {
            IsClosed = true;
            CloseDate = DateTime.UtcNow;
        }

        public void Open()
        {
            if (!IsClosed)
            {
                return;
            }

            if (IsLocked)
            {
                throw new Exception("You can not open a locked issue!");
            }

            IsClosed = true;
            CloseDate = null;
        }

        /// <summary>
        /// 私有构造给程序
        /// </summary>
        public Issue()
        {

        }

        /// <summary>
        /// 有参构造给自己
        /// </summary>
        /// <param name="id"></param>
        /// <param name="assignedUserId"></param>
        /// <param name="title"></param>
        /// <param name="text"></param>
        public Issue(Guid id, Guid assignedUserId, string title, string? text = null) : base(id)
        {
            AssignedUserId = assignedUserId;
            Title = title;
            Description = text;
        }
    }
}
